<?php
echo validation_errors();
$form = array(
    'id'    => 'form-fixture',
    'class' => 'ut-form'
);
$godz = array(
    '18:30',
    '19:00',
    '19:30',
    '20:00',
    '20:30',
    '21:00',
    '21:30',
    '22:00'
);
echo form_open('league/insert_fixture',$form);
echo form_fieldset();
echo '<ul>';
echo '<li>'.form_label('Wybierz ligę:','liga').form_dropdown('liga',$ligi,$this->config->item('ut_liga')).'</li>';
if(!empty($sezony))
    $miasta = '<li>'.form_radio('year','lista',TRUE).form_label('Wybierz sezon:','lyear').form_dropdown('lyear',$sezony,set_value('lyear',date('Y'))).'</li>'
             .'<li>'.form_radio('year','input',FALSE).form_label('Wpisz nazwę:','iyear').form_input(array('name'=>'iyear','placeholder'=>'Rok sezonu','class'=>'small','disabled'=>'disabled'),set_value('iyear')).'</li>';
else
    $miasta = '<li>'.form_label('Wpisz nazwę:','iyear').form_input(array('name'=>'iyear','placeholder'=>'Rok sezonu','class'=>'small'),set_value('iyear')).'</li>';
echo $miasta;
echo '<li>'.form_label('Data kolejki: ','fixt_date').'<input type="date" name="fixt_date" class="small ut-datepicker" value="'.set_value('fixt_date').'" id="fixt-datepicker" placeholder="RRRR-MM-DD"/></li>';
//liczba drużyn w lidze
$nr_teams= count($teams);
//liczba kolejek w sezonie
$nr_fixt = ($nr_teams-1)*2;
//liczba meczy w kolejce
$nr_games= ($nr_teams - ($nr_teams%2))/2;

$numery = array();
for($i=1;$i<=$nr_fixt; $i++)
    $numery[$i] = $i;

echo '<li>'.form_label('Numer kolejki','fixt_number').form_dropdown('fixt_number',$numery).'</li>';
?>
<li>
    <table class="table table-striped table-condensed span6">
        <thead>
            <tr>
                <th>Gospodarz</th>
                <th colspan="3" style="text-align: center;">Wynik</th>
                <th>Gość</th>
                <th>Godzina</th>
            </tr>
        </thead>
        <tbody>
            <?php
            for($i=0; $i<$nr_games; $i++)
            {
                echo '<tr>'
                        .'<td>'.form_dropdown('gosp['.$i.']',$teams).'</td>'
                        .'<td class="small">'.form_input('gosp-gol['.$i.']',set_value('gosp['.$i.']'),'class="small"').'</td>'
                        .'<td>:</td>'
                        .'<td class="small">'.form_input('gosc-gol['.$i.']',set_value('gosc['.$i.']'),'class="small"').'</td>'
                        .'<td>'.form_dropdown('gosc['.$i.']',$teams).'</td>'
                        .'<td class="small">'.form_input('godz['.$i.']',set_value('godz['.$i.']',$godz[$i]),'class="small"').'</td>'
                    .'</tr>';
            }
            ?>
        </tbody>
    </table>
</li>
</ul>
<?php
echo '<p class="clear">'.form_submit('add_fixture','Dodaj kolejkę','class="btn-primary btn-large"').'</p>';
echo form_fieldset_close();
echo form_close();
?>
<script>
$(function(){
    $('input:radio[name=year]').on('change',function(){
        if($(this).val()=='lista'){
            $('input[name=iyear]').prop('disabled',true);
            $('select[name=lyear]').removeProp('disabled');
        }
        else{
            $('input[name=iyear]').removeProp('disabled');
            $('select[name=lyear]').prop('disabled',true);
        }
    });
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>